import functools


@functools.lru_cache(maxsize=2)
def expensive(a, b):
    print('expensive({}, {})'.format(a, b))
    return a * b


def make_call(a, b):
    print('({}, {})'.format(a, b), end=' ')
    pre_hits = expensive.cache_info().hits
    expensive(a, b)
    post_hits = expensive.cache_info().hits
    if post_hits > pre_hits:
        print('cache hit')


print('establish the cache')
make_call(1, 2)
make_call(2, 3)

print('\nused cache items')
make_call(1, 2)
make_call(2, 3)

print('\ncompute a bew value, triggering cache expiration')
make_call(3, 4)

print('\ncache still contains one old item')
make_call(2, 3)

print('\noldest item needs to be computed')
make_call(1, 2)
